// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { Palette, ScrollView, VerticalBox }  from "std-widgets.slint";

import { Api, PropertyContainer } from "../api.slint";
import { ExpandableGroup } from "../components/expandable-group.slint";
import { PreviewDataPropertyValueWidget } from "../components/property-widgets.slint";
import { EditorSpaceSettings } from "../components/styling.slint";

export component PreviewDataView inherits ScrollView {

    property <[PropertyContainer]> preview-data <=> Api.preview-data;

    property <length> key-width: self.width / 2.5;
    property <bool> element-loaded: root.preview-data.length > 0;

    content-layer := VerticalLayout {
        alignment: start;

        if !root.element-loaded: Text {
            text: @tr("Waiting for preview to load");
            horizontal-alignment: center;
            vertical-alignment: center;
            vertical-stretch: 1;
        }
        for ep in root.preview-data: ExpandableGroup {
            enabled: root.enabled;

            text: ep.container-name;
            panel-width: root.width;

            open: ep.properties.length != 0;

            VerticalLayout {
                spacing: EditorSpaceSettings.property-spacing;
                padding: EditorSpaceSettings.default-padding;

                if ep.properties.length == 0 && root.element-loaded: Text {
                    width: 100%;
                    horizontal-alignment: center;

                    text: @tr("No \"in\", \"in-out\", or \"out\" property declared.");
                }
                for p in ep.properties: PreviewDataPropertyValueWidget {
                    preview-data: p;
                    property-container-id: ep.container-id;
                }
            }
        }
    }

    Rectangle {
        x: 0;
        width: 1px;
        background: Palette.border;
    }
}

